package com.bluedot.bank.action;

import com.bluedot.bank.dao.Pagination;
import com.bluedot.bank.dao.exchangerecord.ExchangeRecord;
import com.bluedot.bank.dao.exchangerecord.ExchangeRecordDao;
import com.bluedot.bank.dao.exchangerecord.ExchangeRecordDaoImpl;
import com.bluedot.bank.dao.exchangerecord.RecordFilter;
import com.opensymphony.xwork2.ActionSupport;

public class FindRecordAction extends ActionSupport {
	private RecordFilter recordFilter;
	private Pagination<ExchangeRecord> pagination;
	/**
	 * @return the recordFilter
	 */
	public RecordFilter getRecordFilter() {
		return recordFilter;
	}
	/**
	 * @param recordFilter the recordFilter to set
	 */
	public void setRecordFilter(RecordFilter recordFilter) {
		this.recordFilter = recordFilter;
	}
	/**
	 * @return the pagination
	 */
	public Pagination<ExchangeRecord> getPagination() {
		return pagination;
	}
	/**
	 * @param pagination the pagination to set
	 */
	public void setPagination(Pagination<ExchangeRecord> pagination) {
		this.pagination = pagination;
	}
	
	@Override
	public String execute() throws Exception {
		if (this.pagination == null) {
			this.pagination = new Pagination<ExchangeRecord>();
		}

		if (this.pagination.getSize() == 0) {
			this.pagination.setSize(3);
		}

		if (this.pagination.getNo() == 0) {
			this.pagination.setNo(1);
		}
		
		if("1".equals(recordFilter.getOrderFieldName())){
			this.pagination.setOrderFieldName("asc");
			this.pagination.setDesc(false);
		}else if("1".equals(recordFilter.getOrderFieldName())){
			this.pagination.setOrderFieldName("desc");
			this.pagination.setDesc(true);
		}
		this.pagination.setConditon(recordFilter);
		ExchangeRecordDao recordDao=new ExchangeRecordDaoImpl();
		recordDao.browse(pagination);
		return SUCCESS;
	}


}
